//
//  PostHuoDongViewController.m
//  XRSquare
//
//  Created by UaenaMo on 2018/8/16.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "PostHuoDongViewController.h"
#import "ClassViewController.h"
#import "PGDatePickManager.h"
#import <Qiniu/QiniuSDK.h>
#import "CityViewController.h"

@interface PostHuoDongViewController ()<classSelectDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,PGDatePickerDelegate,citySelectDelegate,UIScrollViewDelegate>
{
    UIScrollView * contentScrollView;

    UIButton * typeButton;
    UILabel * typeLabel;
    UILabel * typeContent;
    
    UILabel * titleLabel;
    UITextField * titleContent;

    UILabel * photoLabel;
    UIImageView * photoImage;
    
    UILabel * numberLabel;
    UITextField * numberTextField;
    
    UILabel * evTime;
    UIButton * evStart;
    UILabel * toLabel;
    UIButton * evEnd;
    
    UILabel * subEndLabel;
    UILabel * subEndContent;
    UIButton * subEndTime;
    
    UILabel * secureLabel;
    UIButton * all;
    UIButton * friend;

    UILabel * eventType;
    UILabel * eventContent;
    UIButton * eventButton;
    
    UILabel * eventSheng;
    UILabel * eventShengContent;
    UIButton * eventShengButton;
    
    UILabel * eventLocation;
    UITextField * eventLocationContent;
    
    UILabel * eventDescribeLabel;
    UITextField * eventDescribeContent;

    UILabel * eventApproveLabel;
    UITextField * eventApproveContent;
    
    UILabel * speTreatLabel;
    UITextField * speTreatTextfield;
    
    NSString * pic;
    NSString * begintime;
    NSString * endtime;
    NSString * deadtime;
    NSString * showtype;
    NSString * onoffline;
    NSString * addressid;
    NSString * addressdetail;
    NSString * description;
    NSString * demand;
    NSString * class;
    NSString * payment;
    NSString * paymentarg;
    NSString * type;
    NSString * jobtitle;
}
@end

@implementation PostHuoDongViewController

-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"发布" style:UIBarButtonItemStylePlain target:self action:@selector(postAction)];

    self.navigationItem.title = @"发布活动";
    
    CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
    CGRect rectNav = self.navigationController.navigationBar.frame;
    
    contentScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, rectNav.size.height + rectStatus.size.height, ScreenWidth, ScreenHeight - rectNav.size.height - rectStatus.size.height)];
    contentScrollView.delegate = self;
    [self.view addSubview:contentScrollView];
    
    CGFloat height = 0;
    
    typeButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 70)];
    [typeButton addTarget:self action:@selector(typeSelect) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:typeButton];
    
    typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, ScreenWidth, 20)];
    typeLabel.font = [UIFont systemFontOfSize:15];
    typeLabel.text = @"活动分类";
    [contentScrollView addSubview:typeLabel];
    
    typeContent = [[UILabel alloc]initWithFrame:CGRectMake(10, 40, ScreenWidth, 20)];
    typeContent.font = [UIFont systemFontOfSize:15];
    typeContent.text = @"请选择分类";
    typeContent.textColor = [UIColor colorFromHexCode:@"b3b3b3"];
    [contentScrollView addSubview:typeContent];
    
    UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, 70, ScreenWidth, 1)];
    line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line];
    
    height += 70;
    
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    titleLabel.font = [UIFont systemFontOfSize:15];
    titleLabel.text = @"活动标题";
    [contentScrollView addSubview:titleLabel];
    
    titleContent = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 20)];
    titleContent.font = [UIFont systemFontOfSize:15];
    titleContent.placeholder = @"请输入活动标题";
    [contentScrollView addSubview:titleContent];
    
    UIView * line1 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line1.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line1];
    
    height += 70;
    
    photoLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    photoLabel.font = [UIFont systemFontOfSize:15];
    photoLabel.text = @"活动图片";
    [contentScrollView addSubview:photoLabel];
    
    photoImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth - 20, 60)];
    photoImage.contentMode = UIViewContentModeScaleAspectFill;
    photoImage.clipsToBounds = YES;
    photoImage.userInteractionEnabled = YES;
    [contentScrollView addSubview:photoImage];
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imageAction)];
    [photoImage addGestureRecognizer:tap];
    
    UIView * line0 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 110, ScreenWidth, 1)];
    line0.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line0];
    
    height += 120;
    
    numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    numberLabel.font = [UIFont systemFontOfSize:15];
    numberLabel.text = @"活动人数";
    [contentScrollView addSubview:numberLabel];
    
    numberTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 20)];
    numberTextField.font = [UIFont systemFontOfSize:15];
    numberTextField.placeholder = @"请输入活动人数";
    numberTextField.keyboardType = UIKeyboardTypeNumberPad;
    [contentScrollView addSubview:numberTextField];
    
    UIView * line09 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line09.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line09];
    
    height += 70;
    
    evTime = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    evTime.font = [UIFont systemFontOfSize:15];
    evTime.text = @"活动时间";
    [contentScrollView addSubview:evTime];
    
    evStart = [[UIButton alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth/2 - 50, 20)];
    evStart.titleLabel.font = [UIFont systemFontOfSize:15];
    [evStart setTitleColor:[UIColor colorFromHexCode:@"b3b3b3"] forState:UIControlStateNormal];
    [evStart setTitle:@"活动开始时间" forState:UIControlStateNormal];
    [evStart addTarget:self action:@selector(startTime) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:evStart];
    
    toLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2 - 10, height + 40, 20, 20)];
    toLabel.font = [UIFont systemFontOfSize:15];
    toLabel.textAlignment = NSTextAlignmentCenter;
    toLabel.text = @"to";
    [contentScrollView addSubview:toLabel];
    
    evEnd = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2 + 10, height + 40, ScreenWidth/2 - 50, 20)];
    evEnd.titleLabel.font = [UIFont systemFontOfSize:15];
    [evEnd setTitleColor:[UIColor colorFromHexCode:@"b3b3b3"] forState:UIControlStateNormal];
    [evEnd setTitle:@"活动结束时间" forState:UIControlStateNormal];
    [evEnd addTarget:self action:@selector(endTime) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:evEnd];
    
    UIView * line3 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line3.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line3];
    
    height += 70;
    
    subEndTime = [[UIButton alloc]initWithFrame:CGRectMake(0, height, ScreenWidth, 70)];
    [subEndTime addTarget:self action:@selector(subEndTime) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:subEndTime];
    
    subEndLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    subEndLabel.font = [UIFont systemFontOfSize:15];
    subEndLabel.text = @"报名截止";
    [contentScrollView addSubview:subEndLabel];
    
    subEndContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 20)];
    subEndContent.font = [UIFont systemFontOfSize:15];
    subEndContent.text = @"请选择报名截止时间";
    subEndContent.textColor = [UIColor colorFromHexCode:@"b3b3b3"];
    [contentScrollView addSubview:subEndContent];
    
    UIView * line66 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line66.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line66];
    
    height += 70;
    
    secureLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    secureLabel.font = [UIFont systemFontOfSize:15];
    secureLabel.text = @"保密性";
    [contentScrollView addSubview:secureLabel];
    
    all = [[UIButton alloc]initWithFrame:CGRectMake(10, height + 40, 80, 20)];
    [all addTarget:self action:@selector(allAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:all];
    
    friend = [[UIButton alloc]initWithFrame:CGRectMake(10 + 90, height + 40, 90, 20)];
    [friend addTarget:self action:@selector(friendAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:friend];
    
    UIView * line6 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line6.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line6];
    
    all.layer.cornerRadius = 10;
    all.layer.borderColor = themeColor.CGColor;
    all.layer.borderWidth = 1;
    all.titleLabel.font = [UIFont systemFontOfSize:15];
    [all setTitleColor:themeColor forState:UIControlStateNormal];
    [all setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [all setTitle:@"全部可见" forState:UIControlStateNormal];
    all.clipsToBounds = YES;
    
    friend.layer.cornerRadius = 10;
    friend.layer.borderColor = themeColor.CGColor;
    friend.layer.borderWidth = 1;
    friend.titleLabel.font = [UIFont systemFontOfSize:15];
    [friend setTitleColor:themeColor forState:UIControlStateNormal];
    [friend setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [friend setTitle:@"仅好友可见" forState:UIControlStateNormal];
    friend.clipsToBounds = YES;
    
    height += 70;
    
    eventButton = [[UIButton alloc]initWithFrame:CGRectMake(0, height, ScreenWidth, 70)];
    [eventButton addTarget:self action:@selector(xingshiAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:eventButton];
    
    eventType = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    eventType.font = [UIFont systemFontOfSize:15];
    eventType.text = @"活动形式";
    [contentScrollView addSubview:eventType];
    
    eventContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 20)];
    eventContent.font = [UIFont systemFontOfSize:15];
    eventContent.text = @"请选择活动形式";
    eventContent.textColor = [UIColor colorFromHexCode:@"b3b3b3"];
    [contentScrollView addSubview:eventContent];
    
    UIView * line7 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line7.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line7];
    
    height += 70;
    
    eventShengButton = [[UIButton alloc]initWithFrame:CGRectMake(0, height, ScreenWidth, 70)];
    [eventShengButton addTarget:self action:@selector(shengshiAction) forControlEvents:UIControlEventTouchUpInside];
    [contentScrollView addSubview:eventShengButton];
    
    eventSheng = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    eventSheng.font = [UIFont systemFontOfSize:15];
    eventSheng.text = @"活动省市";
    [contentScrollView addSubview:eventSheng];
    
    eventShengContent = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 20)];
    eventShengContent.font = [UIFont systemFontOfSize:15];
    eventShengContent.text = @"请选择省市区";
    eventShengContent.textColor = [UIColor colorFromHexCode:@"b3b3b3"];
    [contentScrollView addSubview:eventShengContent];
    
    UIView * line8 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line8.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line8];
    
    height += 70;
    
    eventLocation = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    eventLocation.font = [UIFont systemFontOfSize:15];
    eventLocation.text = @"详细地址";
    [contentScrollView addSubview:eventLocation];
    
    eventLocationContent = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 20)];
    eventLocationContent.font = [UIFont systemFontOfSize:15];
    eventLocationContent.placeholder = @"请输入详细地址";
    [contentScrollView addSubview:eventLocationContent];
    
    UIView * line17 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line17.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line17];
    
    height += 70;
    
    eventDescribeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    eventDescribeLabel.font = [UIFont systemFontOfSize:15];
    eventDescribeLabel.text = @"详细描述";
    [contentScrollView addSubview:eventDescribeLabel];
    
    eventDescribeContent = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 20)];
    eventDescribeContent.font = [UIFont systemFontOfSize:15];
    eventDescribeContent.placeholder = @"请输入详细描述";
    [contentScrollView addSubview:eventDescribeContent];
    
    UIView * line197 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line197.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line197];
    
    height += 70;
    
    eventApproveLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    eventApproveLabel.font = [UIFont systemFontOfSize:15];
    eventApproveLabel.text = @"活动要求";
    [contentScrollView addSubview:eventApproveLabel];
    
    eventApproveContent = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 20)];
    eventApproveContent.font = [UIFont systemFontOfSize:15];
    eventApproveContent.placeholder = @"请输入活动要求";
    [contentScrollView addSubview:eventApproveContent];
    
    UIView * line1907 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line1907.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line1907];
    
    height += 70;
    
    speTreatLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, height + 10, ScreenWidth, 20)];
    speTreatLabel.font = [UIFont systemFontOfSize:15];
    speTreatLabel.text = @"特殊福利";
    [contentScrollView addSubview:speTreatLabel];
    
    speTreatTextfield = [[UITextField alloc]initWithFrame:CGRectMake(10, height + 40, ScreenWidth, 20)];
    speTreatTextfield.font = [UIFont systemFontOfSize:15];
    speTreatTextfield.placeholder = @"请输入特殊福利";
    [contentScrollView addSubview:speTreatTextfield];
    
    UIView * line19507 = [[UIView alloc]initWithFrame:CGRectMake(0, height + 70, ScreenWidth, 1)];
    line19507.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentScrollView addSubview:line19507];
    
    height += 70;

    contentScrollView.contentSize = CGSizeMake(ScreenWidth, height);
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [titleContent resignFirstResponder];
    [numberTextField resignFirstResponder];
    [eventLocationContent resignFirstResponder];
    [eventDescribeContent resignFirstResponder];
    [eventApproveContent resignFirstResponder];
    [speTreatTextfield resignFirstResponder];
}

-(void)postAction
{
    [SVProgressHUD show];
    [NetRequestCenter uptokenwithbucket:@"0" result:^(BOOL success, NSDictionary *resultDic) {
        if (success)
        {
            NSString * token = [resultDic objectForKey:@"uptoken"];
            UIImage * oriImage = photoImage.image;
            NSData * imageData = UIImageJPEGRepresentation(oriImage, 0.5);
            QNUploadOption * option=[[QNUploadOption alloc] initWithProgressHandler:^(NSString *key, float percent) {
                NSLog(@"key=%@ ,percent=%f",key,percent);
            }];
            
            QNUploadManager * upload=[[QNUploadManager alloc] init];
            
            [upload putData:imageData key:[[token componentsSeparatedByString:@":"]firstObject] token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *res) {
                NSLog(@"statusCode=%d",info.statusCode);
                NSLog(@"%@",res);
                
                if(info.statusCode==200)
                {
                    [NetRequestCenter publicactivityWithuid:@"" classid:class title:titleContent.text pic:key peoplenum:numberTextField.text begintime:begintime endtime:endtime deadtime:deadtime showtype:showtype onoffline:onoffline addressid:addressid addressdetail:eventLocationContent.text description:eventDescribeContent.text demand:eventApproveContent.text class:@"0" payment:@"" paymentarg:@"" type:@"" specialwelf:speTreatTextfield.text jobtitle:@"" result:^(BOOL success, NSDictionary *resultDic) {
                        if (success)
                        {
                            [SVProgressHUD showSuccessWithStatus:@"发布成功"];
                            [self.navigationController popViewControllerAnimated:YES];
                        }
                        else
                        {
                            [SVProgressHUD showErrorWithStatus:[resultDic objectForKey:@"message"]];
                        }
                    }];
                }
                else
                {
                    [SVProgressHUD showErrorWithStatus:[info.error localizedDescription]];
                }
                
            } option:option];
        }
    }];
    
}

-(void)typeSelect
{
    ClassViewController * select = [[ClassViewController alloc]init];
    select.delegate = self;
    [self.navigationController pushViewController:select animated:YES];
}

-(void)selectedClass:(NSString *)classname icd:(NSString *)classid
{
    typeContent.text = classname;
    class = classid;
}

-(void)startTime
{
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.isShadeBackgroud = true;
    PGDatePicker *datePicker = datePickManager.datePicker;
    datePicker.delegate = self;
    datePicker.tag = 1;
    datePicker.datePickerType = PGPickerViewType2;
    datePicker.datePickerMode = PGDatePickerModeDateHourMinute;
    [self presentViewController:datePickManager animated:false completion:nil];
    
    [datePicker setDate:[NSDate date] animated:NO];
}

-(void)endTime
{
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.isShadeBackgroud = true;
    PGDatePicker *datePicker = datePickManager.datePicker;
    datePicker.delegate = self;
    datePicker.tag = 2;
    datePicker.datePickerType = PGPickerViewType2;
    datePicker.datePickerMode = PGDatePickerModeDateHourMinute;
    [self presentViewController:datePickManager animated:false completion:nil];
    
    [datePicker setDate:[NSDate date] animated:NO];
}

-(void)subEndTime
{
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.isShadeBackgroud = true;
    PGDatePicker *datePicker = datePickManager.datePicker;
    datePicker.delegate = self;
    datePicker.tag = 3;
    datePicker.datePickerType = PGPickerViewType2;
    datePicker.datePickerMode = PGDatePickerModeDateHourMinute;
    [self presentViewController:datePickManager animated:false completion:nil];
    
    [datePicker setDate:[NSDate date] animated:NO];
}

-(void)allAction
{
    all.selected = YES;
    friend.selected = NO;
    showtype = @"0";
    all.backgroundColor = themeColor;
    friend.backgroundColor = [UIColor whiteColor];
}

-(void)friendAction
{
    all.selected = NO;
    friend.selected = YES;
    showtype = @"1";
    friend.backgroundColor = themeColor;
    all.backgroundColor = [UIColor whiteColor];
}

-(void)xingshiAction
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
                                                                             message:nil
                                                                      preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction * item1 = [UIAlertAction actionWithTitle:@"线上" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        eventContent.text = @"线上";
        onoffline = @"1";
    }];
    UIAlertAction * item2 = [UIAlertAction actionWithTitle:@"线下" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        eventContent.text = @"线下";
        onoffline = @"0";
    }];
    UIAlertAction * item3 = [UIAlertAction actionWithTitle:@"线下/线上" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        eventContent.text = @"线下/线上";
        onoffline = @"2";
    }];
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    
    [alertController addAction:item1];
    [alertController addAction:item2];
    [alertController addAction:item3];
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

-(void)shengshiAction
{
    CityViewController * city = [[CityViewController alloc]init];
    city.delegate = self;
    city.citySA = NO;
    [self.navigationController pushViewController:city animated:YES];
}

-(void)city:(NSString *)city province:(NSString *)province dis:(NSString *)dis code:(NSString *)code cityCode:(NSString *)cityCode
{
    eventShengContent.text = [NSString stringWithFormat:@"%@ %@ %@",province,city,dis];
    addressid = code;
}

-(void)imageAction
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
                                                                             message:nil
                                                                      preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction * timeOrder = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        UIImagePickerController * imagePicker = [[UIImagePickerController alloc]init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.allowsEditing = YES;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }];
    UIAlertAction * collectionOrder = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        UIImagePickerController * imagePicker = [[UIImagePickerController alloc]init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.allowsEditing = YES;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }];
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"Cancel Action");
    }];
    
    [alertController addAction:timeOrder];
    [alertController addAction:collectionOrder];
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    UIImage * selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    
    photoImage.image = selectedImage;
    
    [self dismissViewControllerAnimated:picker completion:nil];
}

#pragma PGDatePickerDelegate
- (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents {
    NSLog(@"dateComponents = %@", dateComponents);
    
    NSCalendar * calendar = [NSCalendar currentCalendar];
    NSDate * date = [calendar dateFromComponents:dateComponents];
    
    if (datePicker.tag == 1)
    {
        begintime = [NSString stringWithFormat:@"%ld-%02ld-%02ld %02ld:%02ld",(long)dateComponents.year,(long)dateComponents.month,dateComponents.day,dateComponents.hour,dateComponents.minute];
        [evStart setTitle:begintime forState:UIControlStateNormal];
        begintime = [[[NSString stringWithFormat:@"%f",date.timeIntervalSince1970]componentsSeparatedByString:@"."]firstObject];
    }
    if (datePicker.tag == 2)
    {
        endtime = [NSString stringWithFormat:@"%ld-%02ld-%02ld %02ld:%02ld",(long)dateComponents.year,(long)dateComponents.month,dateComponents.day,dateComponents.hour,dateComponents.minute];
        [evEnd setTitle:endtime forState:UIControlStateNormal];
        endtime = [[[NSString stringWithFormat:@"%f",date.timeIntervalSince1970]componentsSeparatedByString:@"."]firstObject];
    }
    if (datePicker.tag == 3)
    {
        deadtime = [NSString stringWithFormat:@"%ld-%02ld-%02ld %02ld:%02ld",(long)dateComponents.year,(long)dateComponents.month,dateComponents.day,dateComponents.hour,dateComponents.minute];
        subEndContent.text = deadtime;
        deadtime = [[[NSString stringWithFormat:@"%f",date.timeIntervalSince1970]componentsSeparatedByString:@"."]firstObject];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
